<?php
/**
 * Created by PhpStorm.
 * User: 76683
 * Date: 2018/7/16
 * Time: 23:02
 */

namespace app\sd\model;


use think\Model;

class WeTopic extends Model
{
    protected $autoWriteTimestamp = true;

    public static function topicList($map, $order = 'create_time desc')
    {
        $map['t.is_delete'] = 0;
        $field = 't.id,t.create_time,t.user_id,t.update_time,t.content,t.photos,t.likes,t.details,c.name as category_name';
        $field .= ',u.nick_name,u.we_nick_name';
        $model = new self();
        $data_list = $model->alias('t')
            ->field($field)
            ->join('__WE_CATEGORY__ c', 't.category_id = c.id')
            ->join('__WE_USERS__ u', 't.user_id = u.id')
            ->where($map)
            ->order($order)
            ->paginate(20);
        return $data_list;
    }

    public function topicDetail()
    {
        return $this->hasMany('TopicDetail', 'topic_id', 'id')->where(['status' => 1]);
    }
}